﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
using UtilZ.Dotnet.Ex.ZLog;

namespace UtilZ.Dotnet.Ex.Base
{
    /// <summary>
    /// 扩展线程接口
    /// </summary>
    public interface IThreadEx : IDisposable
    {
        /// <summary>
        /// 获取内部线程
        /// </summary>
        Thread OwnerThread { get; }

        /// <summary>
        /// 启动线程
        /// </summary>
        /// <param name="obj">线程启动参数</param>
        void Start(object obj = null);

        /// <summary>
        /// 停止线程
        /// </summary>
        void Stop();

        /// <summary>
        /// 同步停止线程
        /// </summary>
        /// <param name="timeoutMilliseconds">同步超时时间,-1表示无限期等待,单位/毫秒</param>
        /// <returns>如果线程已终止，则为 true；如果 false 参数指定的时间量已过之后还未终止线程，则为 timeout</returns>
        bool SyncStop(int timeoutMilliseconds = -1);

        /// <summary>
        /// 线程执行完成事件
        /// </summary>
        event EventHandler<ThreadExCompletedArgs> Completed;

        /// <summary>
        /// 获取线程当前的状态
        /// </summary>
        System.Threading.ThreadState ThreadState { get; }

        /// <summary>
        /// 获取当前托管线程的唯一标识符
        /// </summary>
        int ManagedThreadId { get; }

        /// <summary>
        /// 当前线程是否正在运行
        /// </summary>
        bool IsRuning { get; }
    }

}
